class FactoriesController < ApplicationController
  
  def index
    params[:key_word] = "%#{params[:key_words]}%"
    @factories = Factory.where('name like :key_word',params).visible.order('created_at asc')
  end
  
  def new 
    @factory = Factory.new
  end
  
  def create
    @factory = Factory.new(params[:factory])
    if @factory.save
      redirect_to :action => :index
    else
      render :new
    end
  end
  
  def edit
    @factory = Factory.find(params[:id])
  end
  
  def update
    @factory = Factory.find(params[:id])
    if @factory.update_attributes(params[:factory])
      redirect_to :action => :index
    else
      render :edit
    end
  end
  
  def hide
    @factory = Factory.find(params[:id])
    @factory.hidden!
    redirect_to :action => :index
  end

  def visible
    @factory = Factory.find(params[:id])
    @factory.visible!
    redirect_to :action => :index
  end
end
